package com.example.art_cloud_backend.model.enums;

import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import lombok.Getter;

/**
 * @Author caiya
 * @Description 用户角色枚举类
 * @Version 1.0
 */
@Getter
public enum UserRoleEnum {
    USER("用户", "user"),
    ADMIN("管理员", "admin");

    private final String roleName;
    private final String roleValue;

    UserRoleEnum(String roleName, String roleValue) {
        this.roleName = roleName;
        this.roleValue = roleValue;
    }

    /**
     * 根据枚举值 获取 枚举对象
     * @param roleValue 枚举值
     * @return 枚举对象
     */
    public static UserRoleEnum getEnumByRoleValue(String roleValue) {
        if (ObjectUtil.isEmpty(roleValue)) {
            return null;
        }
        for (UserRoleEnum userRoleEnum : UserRoleEnum.values()) {
            if (userRoleEnum.getRoleValue().equals(roleValue)) {
                return userRoleEnum;
            }
        }
        return null;
    }

}
